package com.aqiang.user_content.presenter;

import com.aqiang.net.BaseObserable;
import com.aqiang.net.BaseObserver;
import com.aqiang.net.entity.BaseEntity;
import com.aqiang.user_content.contract.RegisterContract;
import com.aqiang.user_content.entity.User2Entity;
import com.aqiang.user_content.entity.UserEntity;
import com.aqiang.user_content.model.repository.RegisterRepositroy;

public class RegisterPresenter extends RegisterContract.RegisterPresenter {
    public RegisterPresenter(RegisterContract.RegisterView registerView) {
        super(registerView);
    }

    @Override
    public void requestRegister() {
        UserEntity userEntity = new UserEntity();
        userEntity.setPhoneNum(Integer.parseInt(mView.get().getUser()));
        userEntity.setUserAddress(mView.get().getPwd());
        BaseObserable.doObserable(mRepositroy.requestRegister(userEntity), new BaseObserver<UserEntity>() {
            @Override
            public void ok(UserEntity userEntity) {
                if(mView != null && mView.get() != null){
                    mView.get().succse();
                }
            }
        },mView.get().getLifecycleOwner());
    }

    @Override
    public void request2Register() {
        User2Entity user2Entity = new User2Entity();
        user2Entity.setUsername(mView.get().getUser());
        user2Entity.setPwd(mView.get().getPwd());
        BaseObserable.doObserable(mRepositroy.request2Register(user2Entity), new BaseObserver<BaseEntity<User2Entity>>() {
            @Override
            public void ok(BaseEntity<User2Entity> user2EntityBaseEntity) {
                if(mView != null && mView.get() != null){
                    mView.get().succse();
                }
            }
        },mView.get().getLifecycleOwner());
    }

    @Override
    protected void createRepository() {
        mRepositroy = new RegisterRepositroy();
    }
}
